﻿@using System.Web.Script.Serialization
@model UmbracoGuitarGreb.Models.PublishSong

@{
    var bands = Html.Raw(Json.Encode(Model.Bands.Select(x => x.Name)));

}

<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />
<div id="status">
    @using (Ajax.BeginForm("Publish", "PublishSong", new AjaxOptions
{
    HttpMethod = "POST",
    InsertionMode = InsertionMode.Replace,
    UpdateTargetId = "status",
    OnFailure = "ShowError()",
    OnSuccess = "ShowSuccess()"
}))
    {
        <fieldset>
            <div class="form-group" id="songForm">
                <div class="">
                    @Html.LabelFor(m => m.Title, new { @class = "control-label" })
                    @Html.TextBoxFor(m => m.Title, new { @class = "form-control" })
                    @Html.ValidationMessageFor(m => m.Title, "", new { @class = "text-danger" })
                </div>
                <br />
                <div class="">
                    @Html.LabelFor(m => m.BodyText, new { @class = "control-label" })
                    @Html.TextAreaFor(m => m.BodyText, 15, 1, new { @class = "form-control" })
                    @Html.ValidationMessageFor(m => m.BodyText, "", new { @class = "text-danger" })
                </div>
                <br />
                <div class="">
                    @Html.LabelFor(m => m.SelectedBand, new { @class = "control-label" })
                    @Html.TextBoxFor(m => m.SelectedBand, new { @class = "form-control" })
                    @*<input class="form-control" type="text" id="bands" name="SelectedBand" />*@
                    @Html.ValidationMessageFor(m => m.SelectedBand, "", new { @class = "text-danger" })
                </div>
                <br />
                <div class="">
                    @Html.LabelFor(m => m.SpotifyUri, new { @class = "control-label" })
                    @Html.TextBoxFor(m => m.SpotifyUri, new { @class = "form-control" })
                    @Html.ValidationMessageFor(m => m.SpotifyUri)
                </div>
                <br />
                @if (string.IsNullOrEmpty(ViewBag.MemberName))
                {
                    @Html.Label("Brúkarnavn: Ókendur")
                    <i>Um tú vilt hava títt navn at standa á sanginum, mást tú skráseta brúkara!</i>
                }
                else
                {
                    @Html.Label("Brúkarnavn")
                    <input value="@ViewBag.MemberName" type="text" class="form-control" disabled/>
                }
                <br/>
                <div class="">
                    <input type="submit" value="Send" class="btn btn-default" />
                </div>
            </div>
        </fieldset>
    }
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>



<script type="text/javascript">

    var availableBands = @bands;

    $('#SelectedBand').autocomplete({
        source: availableBands
    });

    function ShowError() {
        $("#status").removeClass();
        $("#status").addClass("alert alert-danger");
        $("#status").html("Okkurt gekk galið. Vinarliga royn aftur seinni.");
    }

    function ShowSuccess() {
        $("#status").removeClass();
        $("#status").addClass("alert alert-success");
        $("#status").html("Takk fyri. Sangurin verur at síggja á síðuni innan heilt stutta tíð!");
    }

</script>


